package com.jf01.controller;

import java.util.List;

import com.jf01.model.Blog;
import com.jfinal.core.Controller;

/**
 * @author Yong
 *
 */
public class BlogController extends Controller {

	public void index(){
		List<Blog> blogs=Blog.dao.find("select * from blog");
		setAttr("blogs", blogs);
		System.out.println(blogs.size()+"个数据");
		render("list.jsp");
	}
	
	public void form(){
		Integer id=getParaToInt(0);
		if (id==null ||id>0) {
			setAttr("blog", Blog.dao.findById(id));
		}
		render("form.jsp");
	}
	
	public void submit(){
		Blog blog=getModel(Blog.class,"blog");
		blog.save();
		redirect("/blog");
	}
	
	public void update(){
		Blog blog=getModel(Blog.class,"blog");
		blog.update();
		redirect("/blog");
	}
	
	public void edit(){
		
		form();
	}
	
	public void del(){
		Blog.dao.deleteById(getPara(0));
		
		redirect("/blog");
	}
}
